/*
 * @Author: zdc 3215400595@qq.com
 * @Date: 2023-07-29 17:39:32
 * @LastEditors: zdc 3215400595@qq.com
 * @LastEditTime: 2023-07-29 18:57:42
 * @FilePath: /Use_of_technology/builder/build.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 通过小米手机的构造理解建造者模式

#include <iostream>
#include <memory>
#include <string>

class Phone
{
public:
    Phone() {}
    void SetBoard(const std::string &board)
    {
        _board = board;
    }
    void SetDisplay(const std::string &display)
    {
        _display = display;
    } 
    virtual void SetOS() = 0;
    void showParemates()
    {
        std::string param = "Phone Paramaters\n";
        param += "\tBoard : " + _board + "\n";
        param += "\tdispaly : " + _board + "\n";
        param += "\tos : " + _os + "\n";
        std::cout << param << std::endl;
    }

protected:
    std::string _board;
    std::string _display;
    std::string _os;
};

class xiaomi : public Phone
{
private:
    void SetOS() override
    {
        _os = "xiao mi 14";
    }
};

class Bulider
{
public:
    virtual void buildBoard(const std::string &board) = 0;
    virtual void buildDisplay(const std::string &Display) = 0;
    virtual void buildOS() = 0;
    virtual std::shared_ptr<Phone> build() = 0;
};

class xiaomiBulider : public Bulider
{
public:
    xiaomiBulider() : _phone(new xiaomi()) {}
    void buildBoard(const std::string &board)
    {
        _phone->SetBoard(board);
    }
    void buildDisplay(const std::string &Display)
    {
        _phone->SetBoard(Display);
    }
    void buildOS()
    {
        _phone->SetOS();
    }
    std::shared_ptr<Phone> build()
    {
        return _phone;
    }

private:
    std::shared_ptr<Phone> _phone;
};

class Director
{
public:
    Director(Bulider *builder) : _builder(builder) {}
    void construct(const std::string &board, const std::string &display)
    {
        _builder->buildBoard(board);
        _builder->buildBoard(display);
        _builder->buildOS();
    }

private:
    std::shared_ptr<Bulider> _builder;
};

int main()
{
    Bulider *bulider = new xiaomiBulider();
    std::unique_ptr<Director> director(new Director(bulider));
    director->construct("华为主板", "oppo显示器");
    std::shared_ptr<Phone> phone = bulider->build();
    phone->showParemates();
    return 0;
}